package com.lesson03;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//主窗口
public class DialogDemo extends JFrame {
    public DialogDemo(){
        this.setVisible(true);
        this.setBounds(300,300,200,200);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //JFrame放东西
        Container container = this.getContentPane();
        //绝对布局
        container.setLayout(null);
        //按钮
        JButton button = new JButton("弹出");
        button.setBounds(50,50,100,50);
        container.add(button);
        //点击按钮，弹出弹窗
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //弹出窗口
                new Dialog(DialogDemo.this);
            }
        });
    }
    public static void main(String[] args) {
        //创建窗口
        new DialogDemo();
    }
}
//弹窗
class Dialog extends JDialog{
    public Dialog(DialogDemo dialogDemo){
        this.setTitle("弹窗");
        this.setVisible(true);
        this.setBounds(300,300,200,200);
    }
}